package com.ttwm.dao;

import com.ttwm.pojo.Order;
import com.ttwm.pojo.OrderFood;
import org.apache.ibatis.annotations.*;
import org.apache.ibatis.annotations.Insert;

import org.springframework.stereotype.Repository;

import java.util.List;

@Repository
public interface OrderDao {

    @Insert("insert into t_order(userId,together,location,paytime,payment) values (#{userId},#{together},#{location},#{paytime},#{payment})")
    int insertOrder(Order order);

    @Select("select * from t_order")
    List<Order> allOrder();

    @Select("select * from t_order where userId=#{userId} order by orderId desc")
    @Results({
            @Result(id = true,property = "orderId",column = "orderId"),
            @Result(property = "orderFoodList",column = "orderId",
                    many = @Many(select = "com.ttwm.dao.OrderFoodDao.allOrderFood"))
    })
    List<Order> allOrderToFood(Order order);

    @Select("select * from t_order where orderId=#{orderId}")
    @Results({
            @Result(id = true,property = "orderId",column = "orderId"),
            @Result(property = "orderFoodList",column = "orderId",
                    many = @Many(select = "com.ttwm.dao.OrderFoodDao.allOrderFood"))
    })
    Order oneOrderToFood(Order order);


//    修改为已支付
    @Update("update t_order set payment=#{payment},together=#{together},paytime=#{paytime},location=#{location} where orderId=#{orderId}")
    int updatePayment(Order order);

    @Delete(" delete from t_order where orderId=#{orderId}")
    int deleteOrder(Order order);

//    修改地址
    @Update("update t_order set location=#{location} where orderId=#{orderId}")
    int updateLocation(Order order);

}
